# 对于分数背包，贪心一定是最优解。  背包如下：

goods = [(60,10),(100,20),(120,30)]
goods.sort(key = lambda x:x[0] /x[1],reverse=True)
def Package(goods,w):
    get_goods = [0 for _ in range(len(goods))]
    get_value = 0
    for i ,(price,weight) in enumerate(goods):
        if w >= weight:
            get_goods[i] = 1
            get_value += price
            w -= weight
        else:
            get_goods[i] = w / weight
            get_value += (price*get_goods[i])
            break
    return get_goods,get_value


print(Package(goods,50))
